package com.xca.is.fragment;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.transition.Fade;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageButton;

import com.xca.is.activity.BaiKeActivity;
import com.xca.is.activity.CollegeActivity;
import com.xca.is.activity.CourierActivity;
import com.xca.is.activity.SoftwareActivity;
import com.xca.is.activity.TrainActivity;
import com.xca.is.activity.TranslateActivity;
import com.xca.is.activity.WallpaperActivity;
import com.xca.is.activity.WeatherActivity;
import com.xca.is.activity.YellowDateActivity;
import com.xca.is.databinding.FragmentMenuBinding;
import com.xca.is.utils.WebViewScriptUtils;

import java.util.Objects;

public class MenuFragment extends Fragment {
    private FragmentMenuBinding binding ;

    private ImageButton[] imageButtons ;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        binding = FragmentMenuBinding.inflate(getLayoutInflater());
        return binding.getRoot() ;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {

        super.onViewCreated(view, savedInstanceState);

        int[] ints = new int[]{10,18,17} ;
        WebViewScriptUtils.htmlContent(ints,binding.menuWeb);

        imageButtons = new ImageButton[]{binding.mBtn1,binding.mBtn2,binding.mBtn3,binding.mBtn4,
         binding.mBtn5 , binding.mBtn6 , binding.mBtn7 , binding.mBtn8, binding.mBtn9 };
        for (int i = 0; i < imageButtons.length; i++){
            onClickListener(i);
        }
    }

    private void onClickListener(int index)
    {
        imageButtons[index].setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = null ;
                switch (index+1){
                    case 1 :
                        intent = new Intent(getActivity(), CollegeActivity.class);
                        break;
                    case 2 :
                        intent = new Intent(getActivity(), TranslateActivity.class);
                        break;
                    case 3 :
                        intent = new Intent(getActivity(), YellowDateActivity.class);
                        break;
                    case 4 :
                        intent = new Intent(getActivity(), WallpaperActivity.class);
                        break;
                    case 5 :
                        intent = new Intent(getActivity(), CourierActivity.class);
                        break;
                    case 6 :
                        intent = new Intent(getActivity(), TrainActivity.class);
                        break;
                    case 7 :
                        intent = new Intent(getActivity(), SoftwareActivity.class);
                        break;
                    case 8 :
                        intent = new Intent(getActivity(), WeatherActivity.class);
                        break;
                    case 9 :
                        intent = new Intent(getActivity(), BaiKeActivity.class);
                        break;
                    default:
                        return;
                }
                requireActivity().startActivity(intent);
            }
        });
    }
}